package com.jmyd.coupon.server.enums;

import com.jmyd.commons.base.vo.LabelVo;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * 优惠券领取类型
 *
 * @author samphin
 * @since 2021-7-14 13:40:20
 */
public enum SceneCouponDrawTypeEnum {
    /**
     * 优惠券领取类型：1、新人注册;2、赠送;3、手动领取
     */
    DISCOUNT(1, "新人注册"),
    FULL_REDUCTION(2, "赠送"),
    FREE(3, "手动领取"),
    ;

    @Getter
    private Integer code;
    @Getter
    private String desc;

    SceneCouponDrawTypeEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static String getByCode(int code) {
        Optional<SceneCouponDrawTypeEnum> optional = Arrays.stream(SceneCouponDrawTypeEnum.values()).filter(en -> en.getCode() == code).findFirst();
        return optional.map(SceneCouponDrawTypeEnum::getDesc).orElse(null);
    }

    public static List<LabelVo> queryList() {
        return Arrays.stream(SceneCouponDrawTypeEnum.values()).map(en -> {
            LabelVo vo = new LabelVo();
            vo.setKey(en.code);
            vo.setValue(en.desc);
            return vo;
        }).collect(Collectors.toList());
    }
}
